﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.Catalog;
using PowerCreator.LMS.Web.Course;

public partial class sysadmin_DL_Project_AddClassNotice : PowerCreator.LMS.Web.Base.WebBasePage
{
    TOClassNotice objClassNotice = new TOClassNotice();
    protected string ClassName = string.Empty;
    VOTOClass voClass = new VOTOClass();
    TOClass objClass = new TOClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}
        if (!IsPostBack)
        {
            InitPage();


            int CID = 0;
            if (Request.QueryString["CID"] != null)
            {
                CID = int.Parse(Request.QueryString["CID"].ToString());
                ViewState["CID"] = CID.ToString();
                voClass = objClass.Load(CID);
                ClassName = voClass.Name;
               
            }


            int NID = 0;
            if (Request.QueryString["NID"] != null)
            {
                NID = int.Parse(Request.QueryString["NID"].ToString());
                ViewState["NID"] = NID.ToString();
                BinderForm(NID);
            }

        }
    }
    protected override void InitPage()
    {
        //lbl_InfoTitle.Text = GetLanageValueByKey("lbl_AddJob_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobName.Text = GetLanageValueByKey("lbl_AddJob_JobName", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_JobDescription.Text = GetLanageValueByKey("lbl_AddJob_JobDescription", PowerCreator.LMS.Language.LanagetItemType.Page);

        //btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        //btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        //base.InitPage();

        //lbl_InfoTitle_AddNewType.Text = GetLanageValueByKey("lab_AddNewType_InfoTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
        //lbl_NewTypeName.Text = GetLanageValueByKey("lab_AddNewType_TypeName", PowerCreator.LMS.Language.LanagetItemType.Page);

        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }




    private void BinderForm(int id)
    {
        VOTOClassNotice vo = new VOTOClassNotice();
        vo = objClassNotice.Load(id);

        txt_Name.Text = vo.NoticeTitle;
        ftb_NewContent.Text = vo.NoticeContent;
        
        if (vo.SetTop)
        {
            radbtn_top_Yes.Checked = true;
            radbtn_top_No.Checked = false;
        }
        else
        {
            radbtn_top_Yes.Checked = false;
            radbtn_top_No.Checked = true;
        }
        if (vo.SetHighLight)
        {
            radbtn_Yes.Checked = true;
            radbtn_No.Checked = false;
        }
        else
        {
            radbtn_Yes.Checked = false;
            radbtn_No.Checked = true;
        }


    }
    private bool CheckPageData()
    {
        string search = string.Format("NoticeTitle = '{0}'", txt_Name.Text.Trim());
        if (ViewState["NID"] != null)
        {
            search += "and ClassNotice_Id<>" + ViewState["NID"].ToString();
        }
        if (objClassNotice.Count(search) != 0)
        {

            //lbl_msg_Error.Text = GetLanageValueByKey("lbl_msg_addjob_aspx_count", PowerCreator.LMS.Language.LanagetItemType.MSG);

            lbl_msg_Error.Text = "<br />" + GetLanageValueByKey("msg_AddNewType_checkMsg", PowerCreator.LMS.Language.LanagetItemType.Page);
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        VOTOClassNotice vo = new VOTOClassNotice();
        if (ViewState["NID"] == null)
        {
            if (ViewState["CID"] != null)
            {
                vo.ClassID = ViewState["CID"].ToString();
                vo.NoticeTitle = txt_Name.Text.Trim();
                vo.NoticeContent = ftb_NewContent.Text.Trim();
                if (radbtn_top_Yes.Checked == true)
                    vo.SetTop = true;
                if (radbtn_top_No.Checked == true)
                    vo.SetTop = false;
                if (radbtn_Yes.Checked == true)
                    vo.SetHighLight = true;
                if (radbtn_No.Checked == true)
                    vo.SetHighLight = false;
                vo.CreatDate = DateTime.Now;
                PowerCreator.LMS.Web.Base.BasePage bpage = new PowerCreator.LMS.Web.Base.BasePage();
                vo.Creator = bpage.GetCreatedByInfo().UserID;
                if (objClassNotice.Add(vo))
                {
                    string url = "ManageClassNotice.aspx?CID=" + ViewState["CID"].ToString();
                    Script.RedirectURL(url);
                }
            }
        }
        else
        {
            if (ViewState["CID"] != null)
            {
                vo = objClassNotice.Load(int.Parse(ViewState["NID"].ToString()));
                vo.ClassID = ViewState["CID"].ToString();
                vo.NoticeTitle = txt_Name.Text.Trim();
                vo.NoticeContent = ftb_NewContent.Text.Trim();
                if (radbtn_top_Yes.Checked == true)
                    vo.SetTop = true;
                if (radbtn_top_No.Checked == true)
                    vo.SetTop = false;
                if (radbtn_Yes.Checked == true)
                    vo.SetHighLight = true;
                if (radbtn_No.Checked == true)
                    vo.SetHighLight = false;
                vo.CreatDate = DateTime.Now;
                PowerCreator.LMS.Web.Base.BasePage bpage = new PowerCreator.LMS.Web.Base.BasePage();
                vo.Creator = bpage.GetCreatedByInfo().UserID;

                if (objClassNotice.Update(vo))
                {
                    string url = "ManageClassNotice.aspx?CID=" + ViewState["CID"].ToString();
                    Script.RedirectURL(url);
                }
            }
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ManageClassNotice.aspx?CID=" + ViewState["CID"].ToString();
        Script.RedirectURL(url);
    }



}
